/* 线程栈示例 */
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

static void *new_thread(void *arg)
{
    int number = *((int*)arg);
    unsigned long int tid = pthread_self();
    printf("当前为<%d>号线程，线程ID<%lud>\n", number, tid);
    return (void*)0;
}

static int nums[5] = {0, 1, 2, 3, 4};

int main(int argc, char *argv[])
{
    pthread_t tid[5];

    /* 创建5个线程 */
    for (int j = 0; j < 5; j++) {
        pthread_create(&tid[j], NULL, new_thread, &nums[j]);
    }

    /* 等待线程结束 */
    for (int j = 0; j < 5; j++) {
        pthread_join(tid[j], NULL); /* 回收线程 */
    }

    exit(0);
}
